<?php
declare(strict_types=1);
/**
 * Created by project.
 * User: huanzipap
 * Date: 2023/5/11
 * Time: 15:01
 */

namespace App\Model;

use Hyperf\Database\Model\Model;

class ActAnswerJoin extends Model
{
    protected ?string $table='act_answer_join';
    public bool $timestamps = false;

    protected array $fillable = [
        'party_id','act_id','uid','play_total_num','play_total_true', 'play_total_score','play_total_score',
        'play_score_up','play_score','play_score_down','play_used_second_up','play_used_second',
        'play_used_second_down','play_time_up','play_time','play_time_down',
        'answer_total_num','answer_total_true','answer_total_score','answer_danxuan','answer_duoxuan',
        'answer_panduan','answer_true','answer_log','answer_used_second_up','answer_used_second',
        'answer_used_second_down','answer_score_up','answer_score','answer_score_down','answer_time_up',
        'answer_time','answer_time_down'
    ];


    public function act(): \Hyperf\Database\Model\Relations\belongsTo
    {
        return $this->belongsTo(Act::class, 'act_id', 'id');
    }


    public function user(): \Hyperf\Database\Model\Relations\BelongsTo
    {
        return $this->belongsTo(User::class, 'uid', 'id');
    }

    /**
     * 获取用户答题log信息
     * @param int $act_id
     * @param int $uid
     * @return object|null
     */
    static function getActAnswerJoin(int $act_id,int $uid): object|null
    {
        return ActAnswerJoin::where([
            'act_id'=>$act_id,
            'uid'=>$uid
        ])->first();
    }


    public function getAnswerTimeAttribute($value): string
    {
        return date('Y-m-d H:i:s',$value);
    }



}